package com.lrkj.sys.controller;

import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.sys.domain.ServiceDict;
import com.lrkj.sys.service.IServiceDictService;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.enums.BusinessType;

/**
 * 服务类型数据字典Controller
 *
 * @author yajun_ren
 * @date 2021-07-31
 */
@RestController
@RequestMapping("/sys/serviceDict")
public class ServiceDictController extends BaseController
{
    @Autowired
    private IServiceDictService serviceDictService;

    /**
     * 查询服务类型数据字典列表
     */
    @ApiOperation(value = "查询服务类型数据字典列表", notes = "查询服务类型数据字典列表")
    @PreAuthorize("@ss.hasPermi('sys:serviceDict:list')")
    @GetMapping("/list")
    public AjaxResult list(ServiceDict serviceDict)
    {
        List<ServiceDict> list = serviceDictService.selectServiceDictList(serviceDict);
        return AjaxResult.success(list);
    }

    /**
     * 导出服务类型数据字典列表
     */
    @ApiOperation(value = "导出服务类型数据字典列表", notes = "导出服务类型数据字典列表")
    @PreAuthorize("@ss.hasPermi('sys:serviceDict:export')")
    @Log(title = "服务类型数据字典", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ServiceDict serviceDict)
    {
        List<ServiceDict> list = serviceDictService.selectServiceDictList(serviceDict);
        ExcelUtil<ServiceDict> util = new ExcelUtil<ServiceDict>(ServiceDict.class);
        return util.exportExcel(list, "服务类型数据字典数据");
    }

    /**
     * 获取服务类型数据字典详细信息
     */
    @ApiOperation(value = "获取服务类型数据字典详细信息", notes = "获取服务类型数据字典详细信息")
    @PreAuthorize("@ss.hasPermi('sys:serviceDict:query')")
    @GetMapping(value = "/{serviceCode}")
    public AjaxResult getInfo(@PathVariable("serviceCode") Long serviceCode)
    {
        return AjaxResult.success(serviceDictService.selectServiceDictById(serviceCode));
    }

    /**
     * 新增服务类型数据字典
     */
    @ApiOperation(value = "新增服务类型数据字典", notes = "新增服务类型数据字典")
    @PreAuthorize("@ss.hasPermi('sys:serviceDict:add')")
    @Log(title = "服务类型数据字典", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceDict serviceDict)
    {
        return toAjax(serviceDictService.insertServiceDict(serviceDict));
    }

    /**
     * 修改服务类型数据字典
     */
    @ApiOperation(value = "修改服务类型数据字典", notes = "修改服务类型数据字典")
    @PreAuthorize("@ss.hasPermi('sys:serviceDict:edit')")
    @Log(title = "服务类型数据字典", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceDict serviceDict)
    {
        return toAjax(serviceDictService.updateServiceDict(serviceDict));
    }

    /**
     * 删除服务类型数据字典
     */
    @ApiOperation(value = "删除服务类型数据字典", notes = "删除服务类型数据字典")
    @PreAuthorize("@ss.hasPermi('sys:serviceDict:remove')")
    @Log(title = "服务类型数据字典", businessType = BusinessType.DELETE)
    @DeleteMapping("/{serviceCodes}")
    public AjaxResult remove(@PathVariable Long[] serviceCodes)
    {
        return toAjax(serviceDictService.deleteServiceDictByIds(serviceCodes));
    }
}
